﻿#include "DialogMeasure.h"
#include "ui_DialogMeasure.h"

namespace Qly {

DialogMeasure::DialogMeasure(MeasureDataSet *dataset, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogMeasure)
{
    ui->setupUi(this);
    m_pDataSet = dataset;
    ui->lineEditMeasureLine->setText(m_pDataSet->m_textTemplate_MeasureLine);
    ui->lineEditMeasurePolyLine->setText(m_pDataSet->m_textTemplate_MeasurePolyline);
    ui->lineEditMeasureParallelLine->setText(m_pDataSet->m_textTemplate_MeasureParalleLine);

    ui->lineEditMeasureCircle2P->setText(m_pDataSet->m_textTemplate_MeasureCircle2P);
    ui->lineEditMeasureCircle3P->setText(m_pDataSet->m_textTemplate_MeasureCircle3P);
    ui->lineEditMeasureCircleCenter->setText(m_pDataSet->m_textTemplate_MeasureCircleCenter);

    ui->lineEditMeasurePolygon->setText(m_pDataSet->m_textTemplate_MeasurePolygon);
    ui->lineEditMeasureRect->setText(m_pDataSet->m_textTemplate_MeasureRect);


    ui->spinBoxMeasureLine->setValue(m_pDataSet->m_unitConvert_MeasureLine.precision());
    ui->spinBoxMeasurePolyLine->setValue(m_pDataSet->m_unitConvert_MeasurePolyLine.precision());
    ui->spinBoxMeasureParallelLine->setValue(m_pDataSet->m_unitConvert_MeasureParallelLine.precision());

    ui->spinBoxMeasureCircle2P->setValue(m_pDataSet->m_unitConvert_MeasureCircle2P.precision());
    ui->spinBoxMeasureCircle3P->setValue(m_pDataSet->m_unitConvert_MeasureCircle3P.precision());
    ui->spinBoxMeasureCircleCenter->setValue(m_pDataSet->m_unitConvert_MeasureCircleCenter.precision());

    ui->spinBoxMeasurePolygon->setValue(m_pDataSet->m_unitConvert_MeasurePolygon.precision());
    ui->spinBoxMeasureRect->setValue(m_pDataSet->m_unitConvert_MeasureRect.precision());

    connect(ui->lineEditMeasureLine, &QLineEdit::textChanged, this, &DialogMeasure::on_lineEdit_textChanged);
    connect(ui->lineEditMeasurePolyLine, &QLineEdit::textChanged, this, &DialogMeasure::on_lineEdit_textChanged);
    connect(ui->lineEditMeasureParallelLine, &QLineEdit::textChanged, this, &DialogMeasure::on_lineEdit_textChanged);
    connect(ui->lineEditMeasureCircle2P, &QLineEdit::textChanged, this, &DialogMeasure::on_lineEdit_textChanged);
    connect(ui->lineEditMeasureCircle3P, &QLineEdit::textChanged, this, &DialogMeasure::on_lineEdit_textChanged);
    connect(ui->lineEditMeasureCircleCenter, &QLineEdit::textChanged, this, &DialogMeasure::on_lineEdit_textChanged);
    connect(ui->lineEditMeasurePolygon, &QLineEdit::textChanged, this, &DialogMeasure::on_lineEdit_textChanged);
    connect(ui->lineEditMeasureRect, &QLineEdit::textChanged, this, &DialogMeasure::on_lineEdit_textChanged);

    connect(ui->spinBoxMeasureLine, qOverload<int>(&QSpinBox::valueChanged), this, &DialogMeasure::on_spinBox_valueChanged);
    connect(ui->spinBoxMeasurePolyLine, qOverload<int>(&QSpinBox::valueChanged), this, &DialogMeasure::on_spinBox_valueChanged);
    connect(ui->spinBoxMeasureParallelLine, qOverload<int>(&QSpinBox::valueChanged), this, &DialogMeasure::on_spinBox_valueChanged);
    connect(ui->spinBoxMeasureCircle2P, qOverload<int>(&QSpinBox::valueChanged), this, &DialogMeasure::on_spinBox_valueChanged);
    connect(ui->spinBoxMeasureCircle3P, qOverload<int>(&QSpinBox::valueChanged), this, &DialogMeasure::on_spinBox_valueChanged);
    connect(ui->spinBoxMeasureCircleCenter, qOverload<int>(&QSpinBox::valueChanged), this, &DialogMeasure::on_spinBox_valueChanged);
    connect(ui->spinBoxMeasurePolygon, qOverload<int>(&QSpinBox::valueChanged), this, &DialogMeasure::on_spinBox_valueChanged);
    connect(ui->spinBoxMeasureRect, qOverload<int>(&QSpinBox::valueChanged), this, &DialogMeasure::on_spinBox_valueChanged);

}

DialogMeasure::~DialogMeasure()
{
    delete ui;
}

void DialogMeasure::on_lineEdit_textChanged(const QString &text)
{
    QLineEdit *p = (QLineEdit *)sender();
    if(p == ui->lineEditMeasureLine)
    {
        m_pDataSet->m_textTemplate_MeasureLine = text;
    }
    else if( p == ui->lineEditMeasurePolyLine )
    {
        m_pDataSet->m_textTemplate_MeasurePolyline = text;
    }
    else if( p == ui->lineEditMeasureParallelLine )
    {
        m_pDataSet->m_textTemplate_MeasureParalleLine = text;
    }
    else if( p == ui->lineEditMeasureCircle2P )
    {
        m_pDataSet->m_textTemplate_MeasureCircle2P = text;
    }
    else if( p == ui->lineEditMeasureCircle3P )
    {
        m_pDataSet->m_textTemplate_MeasureCircle3P = text;
    }
    else if( p == ui->lineEditMeasureCircleCenter )
    {
        m_pDataSet->m_textTemplate_MeasureCircleCenter = text;
    }
    else if( p == ui->lineEditMeasurePolygon )
    {
        m_pDataSet->m_textTemplate_MeasurePolygon = text;
    }
    else if( p == ui->lineEditMeasureRect )
    {
        m_pDataSet->m_textTemplate_MeasureRect = text;
    }

}

void DialogMeasure::on_spinBox_valueChanged(int value)
{
    QSpinBox *p = (QSpinBox *) sender();
    if( p == ui->spinBoxMeasureLine )
    {
        m_pDataSet->m_unitConvert_MeasureLine.setPrecision(value);
    }
    else if( p == ui->spinBoxMeasurePolyLine )
    {
        m_pDataSet->m_unitConvert_MeasurePolyLine.setPrecision(value);
    }
    else if( p == ui->spinBoxMeasureParallelLine )
    {
        m_pDataSet->m_unitConvert_MeasureParallelLine.setPrecision(value);
    }
    else if( p == ui->spinBoxMeasureCircle2P )
    {
        m_pDataSet->m_unitConvert_MeasureCircle2P.setPrecision(value);
    }
    else if( p == ui->spinBoxMeasureCircle3P )
    {
        m_pDataSet->m_unitConvert_MeasureCircle3P.setPrecision(value);
    }
    else if( p == ui->spinBoxMeasureCircleCenter )
    {
        m_pDataSet->m_unitConvert_MeasureCircleCenter.setPrecision(value);
    }
    else if( p == ui->spinBoxMeasureRect )
    {
        m_pDataSet->m_unitConvert_MeasureRect.setPrecision(value);
    }
    else if( p == ui->spinBoxMeasurePolygon )
    {
        m_pDataSet->m_unitConvert_MeasurePolygon.setPrecision(value);
    }
}



}
